Folder level CSV export of Objects for all modules

I have written the below code for exporting certain object along with its atrributes which works ok BUT this is only for the ciurrent Module. How can this be enhanced to export to Folder level (which would have subfolders and Modules under it).

 

NOTE : I saw SmartDXLs [http://www.smartdxl.com/content/?p=590], which does based on GUI.. But I want to have only 2 attributes and no GUI is necessary.

 

odule m = current
Stream outfile = write("C:\\Temp\\"name(m)".csv")

Object o
  outfile << "Requirements Heading," 
  outfile << "Requirements Text," 
  outfile << "VPM,"
  outfile << "COC," "\n"
for o in m do 
{
 if ((exists attribute "VPM") && (exists attribute "COC"))
 {

  outfile << "\""o."object Heading" "\"," 
  outfile << "\""o."object Text" "\"," "\t" 
  outfile << "\""o."VPM" "\"," 
  outfile << "\""o."COC"  "\""
  outfile << "\n"
 }
}
close (outfile)

 


HKrishnan - Tue Nov 24 06:48:10 EST 2015

Re: Folder level CSV export of Objects for all modules
DOORSHAM - Mon Nov 30 12:58:18 EST 2015

look at https://www.ibm.com/developerworks/community/forums/html/topic?id=72402190-5dcf-43c1-8429-faa3cd1f95f0&ps=25

 

this will show you how to interact with all modules

Re: Folder level CSV export of Objects for all modules
HKrishnan - Tue Dec 01 01:49:56 EST 2015

DOORSHAM - Mon Nov 30 12:58:18 EST 2015

look at https://www.ibm.com/developerworks/community/forums/html/topic?id=72402190-5dcf-43c1-8429-faa3cd1f95f0&ps=25

 

this will show you how to interact with all modules

Thanks DOORSHAM

 

 

With the above link, I was able to develop the below code.. which is almost satifying my requirementAngel, not completely thoFrown. Can you please help me in the sorting

Requirement

Export the   "object Heading","object Text","VPM","COC" to a CSV File, where in VPM and COC are Module attributes.which is in '03 View' (as the attributes VPM & COC are the only 1s in this '03 View')

Expected CSV export Format

 

Module Name with Path Requirements Heading Requirements Text VPM COC
/A/B/Module1Name...... adsasdasd asdasdasasda asdasd

NA

NA

NA

AAA

/A/B/Module2Name...... afdsfasd asdf sdf sdfas

NA

NA

NA

AAA

BBB

CCC

Developed Code (which is not exporiting the intended Data) :

 

int count_formals(string folder_path, bool verbose)

{
    Folder f = folder folder_path
    if ( null f ) return -1
 
    Item it
 Stream outfile = write("C:\\Temp\\Test.csv")
    int count = 0
    for it in f do 
 {
         if ( type(it)=="Formal" )                  
        {
                    
                outfile << name(it)"\n"
                m = read(fullName(it), false)   
    load view "03 View"
                string modulName = m."Name" "\n" 
    Object o
    outfile << "Requirements Heading," 
    outfile << "Requirements Text," 
    outfile << "VPM,"
    outfile << "COC," "\n"
    for o in m do 
    {
    string ObjectHeading = o."object Heading"  
    string ObjectText = o."object Text" 
    string VPM = o."VPM"
    string COC = o."COC"
    
    outfile << ObjectHeading "\","
    outfile << ObjectText "\"," 
    outfile << VPM "\","
    outfile << COC "\t"
    }
                count++
        }

    }
    return count
}

string path_project = "/A/B"
int nb_modules = count_formals(path_project, false)
if (nb_modules == -1 ) print "No modules in " path_project "\n"
else print nb_modules " detected modules\n"

 


 

Re: Folder level CSV export of Objects for all modules
Mike.Scharnow - Tue Dec 01 02:25:26 EST 2015

HKrishnan - Tue Dec 01 01:49:56 EST 2015

Thanks DOORSHAM

 

 

With the above link, I was able to develop the below code.. which is almost satifying my requirementAngel, not completely thoFrown. Can you please help me in the sorting

Requirement

Export the   "object Heading","object Text","VPM","COC" to a CSV File, where in VPM and COC are Module attributes.which is in '03 View' (as the attributes VPM & COC are the only 1s in this '03 View')

Expected CSV export Format

 

Module Name with Path Requirements Heading Requirements Text VPM COC
/A/B/Module1Name...... adsasdasd asdasdasasda asdasd

NA

NA

NA

AAA

/A/B/Module2Name...... afdsfasd asdf sdf sdfas

NA

NA

NA

AAA

BBB

CCC

Developed Code (which is not exporiting the intended Data) :

 

int count_formals(string folder_path, bool verbose)

{
    Folder f = folder folder_path
    if ( null f ) return -1
 
    Item it
 Stream outfile = write("C:\\Temp\\Test.csv")
    int count = 0
    for it in f do 
 {
         if ( type(it)=="Formal" )                  
        {
                    
                outfile << name(it)"\n"
                m = read(fullName(it), false)   
    load view "03 View"
                string modulName = m."Name" "\n" 
    Object o
    outfile << "Requirements Heading," 
    outfile << "Requirements Text," 
    outfile << "VPM,"
    outfile << "COC," "\n"
    for o in m do 
    {
    string ObjectHeading = o."object Heading"  
    string ObjectText = o."object Text" 
    string VPM = o."VPM"
    string COC = o."COC"
    
    outfile << ObjectHeading "\","
    outfile << ObjectText "\"," 
    outfile << VPM "\","
    outfile << COC "\t"
    }
                count++
        }

    }
    return count
}

string path_project = "/A/B"
int nb_modules = count_formals(path_project, false)
if (nb_modules == -1 ) print "No modules in " path_project "\n"
else print nb_modules " detected modules\n"

 


 

How do you want to sort?

e.g. Level 1: fullName (it), Level 2: Requirements Heading? or VPM?, Level 3: ??

Generally, for sorting you can use skip lists.

So, in your loops you will not directly print the result to the stream but you will store the line in a skip list with key =sort criteria and value=string to be printed

Skip sk = createString()

put (sk, "03", "ab")
put (sk, "02", "ac")

string p
for p in sk do {
 print p "\n"
}
delete sk

this will print first "ac" and then "ab", as 02 is smaller than 03.

Re: Folder level CSV export of Objects for all modules
HKrishnan - Tue Dec 01 03:55:34 EST 2015

Mike.Scharnow - Tue Dec 01 02:25:26 EST 2015

How do you want to sort?

e.g. Level 1: fullName (it), Level 2: Requirements Heading? or VPM?, Level 3: ??

Generally, for sorting you can use skip lists.

So, in your loops you will not directly print the result to the stream but you will store the line in a skip list with key =sort criteria and value=string to be printed

Skip sk = createString()

put (sk, "03", "ab")
put (sk, "02", "ac")

string p
for p in sk do {
 print p "\n"
}
delete sk

this will print first "ac" and then "ab", as 02 is smaller than 03.

Thanks Mike.Scharnow for the TIP

 

But the sorting which I was / am looking for was in the exported CSV file.

 

Attached is the sample module screenshot.. where in the current view is the 03 View and I am tryiing to export the attributes VPM and COC(which is a Multi-Valued attribute) into the excel for all the Values selected.


Attachments

Ex.jpg

Re: Folder level CSV export of Objects for all modules
HKrishnan - Tue Dec 01 04:03:27 EST 2015

HKrishnan - Tue Dec 01 03:55:34 EST 2015

Thanks Mike.Scharnow for the TIP

 

But the sorting which I was / am looking for was in the exported CSV file.

 

Attached is the sample module screenshot.. where in the current view is the 03 View and I am tryiing to export the attributes VPM and COC(which is a Multi-Valued attribute) into the excel for all the Values selected.

Attached is the expected way of the excel I want to be exported .. wen I run my script all the Multivalued objects are in the next line Frown


Attachments

Excel Export.jpg

Re: Folder level CSV export of Objects for all modules
Mathias Mamsch - Tue Dec 01 17:31:57 EST 2015

HKrishnan - Tue Dec 01 04:03:27 EST 2015

Attached is the expected way of the excel I want to be exported .. wen I run my script all the Multivalued objects are in the next line Frown

Search for fast CSV export you will find the function to escape your data, before sending it to excel. Regards, Mathias

Re: Folder level CSV export of Objects for all modules
HKrishnan - Wed Dec 02 05:59:09 EST 2015

Mathias Mamsch - Tue Dec 01 17:31:57 EST 2015

Search for fast CSV export you will find the function to escape your data, before sending it to excel. Regards, Mathias

Thanks Mathias Mamsch

 

I wasn able to develop the script with the help of search which I did in this Forum and also the DXL reference guide helped me.. Below is the script(anyone can use it ..incase if they have the same requirement) Idea

int count_formals(string folder_path, bool verbose)
{
    Folder f = folder folder_path
    if ( null f ) return -1
    Item it
 Stream outfile = write("C:\\Temp\\Test.csv")
    int count = 0
 outfile << "Module Name & Path,"
 outfile << "Requirements Heading," 
 outfile << "Requirements Text," 
 outfile << "VPM,"
 outfile << "COC," "\n"
    for it in f do 
 {
         if (type(it)=="Formal")                  
        {
   m = read(fullName(it), false)  
   setDefaultViewForModule(m, "03 View")
   load view "03 View"    
   string ModuleName = m."Name" "\n" 
   Object o
   for o in m do 
   {
    if ((exists attribute "VPM") && (exists attribute "COC"))
    {
     string ObjectHeading = o."object Heading"  
     string ObjectText = o."object Text" 
     string VPM = o."VPM"
     string COC = o."COC"
     string Path = path m
     outfile << "\"" Path "/" ModuleName  "\"," 
     outfile << "\"" ObjectHeading "\","
     outfile << "\"" ObjectText "\","
     outfile << "\"" VPM "\","
     outfile << "\"" COC "\"," "\n" 
    }
   }
   count++
        }
    }
    return count
}
string path_project = "<..Folder Path....>"
int nb_modules = count_formals(path_project, false)
if (nb_modules == 0 ) infoBox "No modules in " path_project "\n"
else infoBox  "Export Completed. Total '"nb_modules"' Modules in '"path_project"' is saved to 'C:\\Temp\\Test.csv'"

 

 

Re: Folder level CSV export of Objects for all modules
sush90 - Wed Jun 27 08:16:45 EDT 2018

HKrishnan - Wed Dec 02 05:59:09 EST 2015

Thanks Mathias Mamsch

 

I wasn able to develop the script with the help of search which I did in this Forum and also the DXL reference guide helped me.. Below is the script(anyone can use it ..incase if they have the same requirement) Idea

int count_formals(string folder_path, bool verbose)
{
    Folder f = folder folder_path
    if ( null f ) return -1
    Item it
 Stream outfile = write("C:\\Temp\\Test.csv")
    int count = 0
 outfile << "Module Name & Path,"
 outfile << "Requirements Heading," 
 outfile << "Requirements Text," 
 outfile << "VPM,"
 outfile << "COC," "\n"
    for it in f do 
 {
         if (type(it)=="Formal")                  
        {
   m = read(fullName(it), false)  
   setDefaultViewForModule(m, "03 View")
   load view "03 View"    
   string ModuleName = m."Name" "\n" 
   Object o
   for o in m do 
   {
    if ((exists attribute "VPM") && (exists attribute "COC"))
    {
     string ObjectHeading = o."object Heading"  
     string ObjectText = o."object Text" 
     string VPM = o."VPM"
     string COC = o."COC"
     string Path = path m
     outfile << "\"" Path "/" ModuleName  "\"," 
     outfile << "\"" ObjectHeading "\","
     outfile << "\"" ObjectText "\","
     outfile << "\"" VPM "\","
     outfile << "\"" COC "\"," "\n" 
    }
   }
   count++
        }
    }
    return count
}
string path_project = "<..Folder Path....>"
int nb_modules = count_formals(path_project, false)
if (nb_modules == 0 ) infoBox "No modules in " path_project "\n"
else infoBox  "Export Completed. Total '"nb_modules"' Modules in '"path_project"' is saved to 'C:\\Temp\\Test.csv'"

 

 

Hi HKrishnan

Thanks for the post! 
I'm working on a similar requirement and came across your code since I'm stuck.

I'm trying to export the data of a complete folder in DOORS to Excel via DXL. The above code is being successful in execution, however it is always executing only the last "else infobox". The export is not completed and I'm unable to find any spreadsheet content for the same in the path.

Can you please help me with the same?

Regards